package org.pandaria.war3.w3g.analyseur;

import org.pandaria.war3.log.LogUtil;
import org.pandaria.war3.util.BitsUtil;

/**
 * The player list is an array of PlayerRecords for all additional players
 * (excluding the game host and any computer players).
 * If there is only one human player in the game it is not present at all!
 * Per additional player there is the following structure in the file:
 *
 */
public class PlayerList {

	public PlayerRecord[] playerRecords = new PlayerRecord[12];
	
	public int nbPlayers = 0;
	
	public byte[] bytes_playersList;
	
	public PlayerList(byte[] bytes_playersList) {
		this.bytes_playersList = bytes_playersList;
	}

	public void parse() throws UnknownDataException {
		
		int i = 0;
		LogUtil.getLogger().info("Joueur "+i);
		
		PlayerRecord currentPlayer = new PlayerRecord(this.bytes_playersList);
		currentPlayer.parse();
		playerRecords[i] = currentPlayer;
		
		while (BitsUtil.hexa(currentPlayer.bytes_recordID).equals("16")){
			
			i++;
			LogUtil.getLogger().info("Joueur "+i);
			
			currentPlayer = new PlayerRecord(bytes_playersList);
			currentPlayer.parse();
			playerRecords[i] = currentPlayer;
			
		}
		
	}

}
